<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/27
 * Time: 17:51
 */
function permission_role($id1,$id2){
    return DB::table("permission_role")->where(['permission_id'=>$id1,'role_id'=>$id2])->first();
}
function role_admin($id1,$id2){
    return DB::table("role_admin")->where(['role_id'=>$id1,'admin_id'=>$id2])->first();
}
function is_post(){
    return $_SERVER['REQUEST_METHOD'] == "POST"?true:false;
}
function is_permission($admin_id,$permission_id){
    if($admin_id == 1){
        return true;
    }
    $permission = DB::table("permissions")->where("name",$permission_id)->value("id");
    $role_admin = DB::table("role_admin")->where("admin_id",$admin_id)->pluck('role_id')->toArray();
    $permission_role = DB::table("permission_role")->whereIn('role_id',$role_admin)->pluck('permission_id')->toArray();
    if(in_array($permission,$permission_role)){
        return true;
    }else{
        return false;
    }
}